package com.hbt.orderfood.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.hbt.orderfood.R;
import com.hbt.orderfood.db.DBAdapter;
import com.hbt.orderfood.entitys.User;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RegisterActivity extends AppCompatActivity {

    @BindView(R.id.username)
    EditText username;
    @BindView(R.id.password)
    EditText password;
    @BindView(R.id.register)
    Button register;
    @BindView(R.id.login)
    Button login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.register)
    public void onViewClicked() {
        String username_str = username.getText().toString();
        String password_str = password.getText().toString();
        User user = new User();
        user.setUsername(username_str);
        user.setPassword(password_str);
        new DBAdapter(this).insertUser(user);
        Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_LONG).show();
        username.setText("");
        password.setText("");
    }

    @OnClick(R.id.login)
    public void onclickLogin() {
        Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
        startActivity(intent);
    }
}
